package com.wwz.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.StrUtil;
import com.wwz.entity.Department;
import com.wwz.entity.Result;
import com.wwz.response.DeptList;
import com.wwz.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("dept")
@Api(tags = "部门控制器")
public class DepartmentController {

    @Resource
    private IDepartmentService departmentService;

    @PostMapping("addOrUpData")
    @ApiOperation("添加或修改部门")
    public Result addOrUpData(@RequestBody Department department){
        departmentService.addOrUpData(department);
        return Result.ok("操作成功");
    }

    @GetMapping("list")
    @ApiOperation("查询企业部门列表")
    public Result getList(){
        String companyId = "7ac32217-25bf-459a-b07d-b739c5c33210";
        DeptList list = departmentService.getList(companyId);
        return Result.ok(list);
    }

    @GetMapping("tree")
    @ApiOperation("查询部门树列表")
    public Result getTreeList(){
        List<Tree<String>> treeList = departmentService.getTreeList();
        return Result.ok(treeList);
    }

    @DeleteMapping("del/{id}")
    @ApiOperation("删除部门")
    public Result delete(@PathVariable String id){
        departmentService.delete(id);
        return Result.ok("操作成功");
    }
}
